﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace AwesomeGame.Weapons
{
    public class Bomb
    {
        public delegate void BombEvent(Bomb sender);
        public event BombEvent Exploded;

        public Vector2 Position;
        private TimeSpan _timeCreated = new TimeSpan();
        private Texture2D _sprite;
        private Vector2 _spriteMidpoint;

        public Bomb(Vector2 position)
        {
            Position = position;
            _sprite = Game1.ContentManager.Load<Texture2D>(@"Weapons\Bomb");
            _spriteMidpoint = new Vector2(_sprite.Width / 2, _sprite.Height / 2);
        }

        public void Update(GameTime gameTime)
        {
            if (_timeCreated == new TimeSpan())
                _timeCreated = gameTime.TotalGameTime;
            if (gameTime.TotalGameTime - _timeCreated >= new TimeSpan(0, 0, 5))
                Explode();
        }

        private void Explode()
        {
            if (Exploded != null)
                Exploded(this);
        }

        public void Draw(GameTime gameTime)
        {
            Vector2 screenPosition = Camera.GetScreenPosition(Position);
            Game1.SpriteBatch.Draw(_sprite, screenPosition, null, Color.White, 0f, _spriteMidpoint, 1f, SpriteEffects.None, 0.8f);
        }
    }
}
